var a = require("../../utils/config.js");

Page({
    data: {
        userName: "",
        idCard: "",
        gender: "",
        nation: "",
        birthday: "",
        address: "",
        isOk: !1
    },
    onLoad: function(a) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getUserName: function(a) {
        this.setData({
            userName: a.detail.value
        });
    },
    getIdCard: function(a) {
        this.setData({
            idCard: a.detail.value
        });
    },
    next: function() {
        var a = this;
        a.data.userName ? a.data.idCard ? wx.navigateTo({
            url: "uploadPassport?userName=" + a.data.userName + "&idCard=" + a.data.idCard + "&idCardZImage=" + a.data.idCardZImage + "&address=" + a.data.address + "&sex=" + a.data.gender
        }) : wx.showToast({
            title: "请输入证件号码",
            icon: "none"
        }) : wx.showToast({
            title: "请输入真实姓名",
            icon: "none"
        });
    },
    chooseIdCardZImage: function() {
        var a = this;
        wx.showModal({
            title: "系统提示",
            content: "请将手机横向拍摄，尽量将身份证填满框内",
            success: function(e) {
                e.confirm && wx.chooseImage({
                    count: 1,
                    success: function(e) {
                        a.setData({
                            idCardZImage: e.tempFilePaths[0]
                        }), a.getIdCardInfo();
                    }
                });
            }
        });
    },
    getIdCardInfo: function() {
        var e = this;
        wx.showLoading({
            title: "证件照识别中",
            mask: !0
        }), wx.request({
            url: a.urlList.API_USER_GET_ID_CARD_INFO,
            method: "POST",
            data: {
                userId: wx.getStorageSync("userId"),
                idCardZImage: wx.getFileSystemManager().readFileSync(e.data.idCardZImage, "base64")
            },
            success: function(a) {
                if (wx.hideLoading(), 200 == a.data.status) {
                    var t = a.data.data;
                    "1" == t.code ? (wx.showToast({
                        title: "识别成功"
                    }), e.setData({
                        userName: t.result.name,
                        idCard: t.result.code,
                        gender: t.result.sex,
                        nation: t.result.nation,
                        birthday: t.result.birthday,
                        address: t.result.address,
                        isOk: !0
                    })) : wx.showToast({
                        title: t.msg,
                        icon: "none"
                    });
                } else wx.showToast({
                    title: a.data.message,
                    icon: "none"
                });
            }
        });
    }
});